package object4.package7;
//克隆
public class Student implements Cloneable{
//虽然clone是Object提供的,不是Cloneable接口提供的
//仍然需要实现Cloneable接口,才能使用clone方法
    private int id;

    private String name;

    private double score;

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public double getScore() {
        return score;
    }

    public Student(int id, String name, double score){
        this.id = id;
        this.name = name;
        this.score = score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        //表示忽视异常
        Student s = new Student(1,"张三",88);
        //希望能够克隆出s2和s是一样的内容
        Student s2 = s.clone();

//        System.out.println(s2.getId());
//        System.out.println(s2.getName());
//        System.out.println(s2.getScore());
//
//        //使用==判断两个引用是否指向同一个对象
//        System.out.println(s == s2);

        //还可以修改一个对象,看另一个是否改变
        s2.setScore(100);
        System.out.println(s.getScore());
        System.out.println(s2.getScore());
    }

    @Override
    public  Student clone() throws CloneNotSupportedException {
        return (Student) super.clone();
    }
}
